/*
 * @(#)mainTest.java   09/10/30
 * 
 * Copyright (C) 2009 Ecole des Mines d'Ales
 *
 * This library itfPfP free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This libraritfPitfP distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: yulinz88@gmail.com
 */



package test;

import org.w3c.dom.Document;

import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

//~--- classes ----------------------------------------------------------------

/**
 * class description
 *
 * @version    version 20 oct. 2009
 * @author     Huaxi (Yulin) ZHANG
 */
public class mainTest1 {

    /** Field description */
    private static final String INCLUDE = "Hello, World!";

    /** Field description */
    private static final String XML = "<?xml version=\"1.0\"?>\n"
                                      + "<data xmlns=\"foo\" xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n"
                                      + "<xi:include href=\"include.txt\" parse=\"text\"/>\n" + "</data>\n";

    /**
     * Method description
     *
     * @param args
     * @throws ParserConfigurationException 
     * @throws IOException 
     * @throws SAXException 
     * @throws TransformerException 
     * @throws JAXBException 
     */
    public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, TransformerException, JAXBException {

//      JAXBContext context;
//      try {
//          context = JAXBContext.newInstance("fr.ema.arch3d.xoADL.specification");
//
//          Unmarshaller unmarshaller;
//              unmarshaller = context.createUnmarshaller();
//              //unmarshaller.setValidating(true);
//
//          File file=new File("E://Yulin//Nime//Code//workspace//Arch3D-xoADL//src//main//java//test//test.xml");
//         //"E://Yulin//Nime//Code//workspace//exampleJAXB//src//test//test11.xml"
//          System.out.println("eeeeeeeeeeeee");
//          JAXBElement o=(JAXBElement)unmarshaller.unmarshal(new FileInputStream(file)) ; 
//
//          //System.out.println(((JAXBElement)o).getName());
//          DefaultSpecification spec =(DefaultSpecification)(((JAXBElement)o).getValue());
//          System.out.println(spec.getName());
//          //DefaultSpecification spec =(DefaultSpecification)(((JAXBElement)o).getValue());
//          //System.out.println(spec.getComponentImplementations().getComponentImplementation().get(0).getComponentClass().getName());
//          
//          
////        System.out.println("heeeeeee");
////        ObjectFactory objFactory = new ObjectFactory();
////        DefaultConfiguration c1=new DefaultConfiguration();;
////        Configuration.ComponentImplementations impls = objFactory.createConfigurationComponentImplementations();
////        Configuration.ComponentImplementations.ComponentImplementation impl = objFactory.createConfigurationComponentImplementationsComponentImplementation();
////        c1.setComponentImplementations(impls);
////        ComponentClassImpl ca=new ComponentClassImpl();
////        ca.setName("ca hahaha");
////        impls.getComponentImplementation().add(impl);
////        impl.setComponentClass(ca);
////        impl.setComponentRoleName("cmpCpC hahaha");
////        
////        Marshaller marshaller = context.createMarshaller();
////        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
////                new Boolean(true));
////        JAXBElement oo=new JAXBElement(new QName("http://ema.fr/arch3d/xoADL/xsd","configuration"),Configuration.class,c1);
////        //o.setValue(c1);
////        System.out.println(c1.getComponentImplementations());
////        marshaller.marshal(oo,new FileOutputStream("testout.xml"));
//          
//          
//      } catch( UnmarshalException ue ) {
//          System.out.println( ue );
//      } catch( JAXBException je ) { 
//          je.printStackTrace();
//      } catch( IOException ioe ) {
//          ioe.printStackTrace();
//      }
	
	
//      docBuilder.setEntityResolver(new EntityResolver() {
//      @Override
//      public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
//          if (systemId.endsWith("cmpRole.xml")) {
//              return new InputSource(bbb);
//          }
//
//          return null;
//      }
//  });

	File f=new File("E://Yulin//Nime//Code//workspace//Arch3D-Model//src//main//java//test//test.xml");	

  
        
        JAXBContext context;
     
          context = JAXBContext.newInstance("fr.ema.arch3d.xoadl.specification");

          Unmarshaller unmarshaller;
 
              unmarshaller = context.createUnmarshaller();
              Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
              .newSchema(new File("E:/Yulin/Nime/Code/workspace/Arch3D-xoADL/src/main/resources/fr/ema/arch3d/xoadl/xsd/specification/specification.xsd"));
              unmarshaller.setSchema(schema);
          JAXBElement o=(JAXBElement)unmarshaller.unmarshal(new FileInputStream(f)) ;
 
    }
    
    

}
